<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>leetcode3-7</title>
</head>

<body>
    <script>
        // 1.  
        // 判断输入的数字是否是unly数
        // unly数只能被2,3,5整除
        // 输入:数字 
        // 输出 true/false
        // 距离:8(是)  15(是) 14(2*7不是)
        var isInteger = function(obj) {
            return obj % 1 === 0;
        }
        var unly = function(num) {
            var temp = 0;
            var isInt = false;

            while (num != 1) {
                isInt = false;
                temp = num / 2;
                if (isInteger(temp)) {
                    isInt = true;
                    num = num / 2;
                } else {
                    isInt = false;
                }
                if (isInt == false) {
                    temp = num / 3;
                    if (isInteger(temp)) {
                        isInt = true;
                        num = num / 3;
                    } else {
                        isInt = false;
                    }
                }
                if (isInt == false) {
                    temp = num / 5;
                    if (isInteger(temp)) {
                        isInt = true;
                        num = num / 5;
                    } else {
                        isInt = false;
                    }
                }
                if (isInt == false) {
                    return false;
                }
            }
            return true;
        }
        console.log(unly(14));



        // 2.
        // 判断输入的数字  判断一下,这个数字是否是3的幂
        // 输入 27  (3*3*3)  81((3*3*3*3)  18(3*3*2)--不是
        var threeM = function(num) {
            var istrue = false
            var nums = num
            for (i = 0; i < num; i++) {
                num = num / 3;
                if (num == 1) {
                    istrue = true;
                    break;
                }
            }
            if (istrue == true) {
                console.log("'" + nums + "'是3的幂");
            } else {
                console.log("'" + nums + "'不是3的幂");
            }
        }
        threeM(6);


        // 3.
        // 输入的数字(十进制) ,转成8进制输出
        // 16----20
        // 24---30
        // 33---41
        var eightJZ = function(num) {
            var ret = [];
            var min = num;
            while (num != 0) {
                min = num % 8;
                num = Math.floor(num / 8);
                ret.push(min);
            }
            var retString = "";
            while (ret.length > 0) {
                retString += ret.pop();
            }
            console.log(retString);
        }
        eightJZ(81);


        // 4.
        // 输入一个数组
        // [1,2,3,4]
        // 输出等长的数组
        // [除了当前项请他的项的积]
        // [24,12,8,6]
        var arrc = function(arr) {
            var arrs = [];
            var num = 1;
            var numq = 1;
            var numh = 1;
            for (var i = 0; i < arr.length; i++) {
                for (var j = i + 1; j < arr.length; j++) {
                    numq = numq * arr[j];
                }
                for (var h = 0; h < i; h++) {
                    numh = numh * arr[h];
                }
                num = numq * numh
                arrs.push(num);
                numq = 1;
                numh = 1;
            }
            console.log(arrs);
        }
        arrc([3, 2, 3, 4]);
    </script>
</body>

</html>